﻿using HCore;

namespace MEat
{
    public class GoalArriveToPosition : Goal<Dummy>
    {
        private readonly Vector3 _position;

        public GoalArriveToPosition(Dummy owner, Vector3 position) : base(owner, GoalType.ArriveToPosition)
        {
            _position = position;
        }

        public override void Activate()
        {
            _status = GoalStatus.Active;

            _owner.steer.SetTarget(_position);

            _owner.steer.ArriveOn();
        }

        public override GoalStatus Process()
        {
            ActivateIfInactive();

            if (_owner.IsAtPosition(_position))
            {
                _status = GoalStatus.Completed;
            }

            return _status;
        }

        public override void Terminate()
        {
            _owner.steer.ArriveOff();
            _owner.velocity = Vector3.zero;

            _status = GoalStatus.Completed;
        }
    }
}